package com.swxy.club.controller;


import com.swxy.club.dto.bo.UserBo;
import com.swxy.club.dto.bo.UserPageBo;
import com.swxy.club.result.Result;
import com.swxy.club.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpSession;
import java.util.List;


/**
 * @author 易
 */

@RestController
@RequestMapping("/api")
@RequiredArgsConstructor
@Api(tags = "用户服务")
public class UserController {

    private final UserService userService;

    @GetMapping("/{id}")
    @ApiOperation("查找用户")
    public Result getUser(@PathVariable("id") String id) {
        return Result.success(userService.getUserByIdNumber(id));
    }

    @PostMapping("/adduser")
    @ApiOperation("添加用户")
    public Result addUser(@RequestBody UserBo form,HttpSession session) {
        userService.addUser(form,session);
        return Result.success("添加成功");
    }

    @PostMapping("/upload")
    @ApiOperation("头像上传")
    public Result upload(@RequestParam("file") MultipartFile file) {
        String avatar = userService.uploadImage(file);
        return Result.success("添加成功",avatar);
    }

    @GetMapping("/currenUser")
    @ApiOperation("获取当前登入用户信息")
    public Result selectCurrenUser(HttpSession session) {
        return Result.success(userService.getCurrentUser(session));
    }

    @GetMapping("/users")
    @ApiOperation("获取多个用户")
    public Result selectUsers(@RequestParam("ids") List<Long> ids ) {
        return Result.success(userService.selectUsers(ids));
    }

    @PostMapping("/pageSelect")
    @ApiOperation("分页查询用户")
    public Result pageSelect(@RequestBody UserPageBo form) {
        return Result.success(userService.pageSelect(form));
    }

}
